home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / doFluidsDiskCache.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.7 KB  |  217 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  20 Feb 2002
  22. //
  23. //  Description:
  24. //      Create Fluids Playback + Render cache
  25. //        
  26. //
  27. global proc setupActiveFluidPBCaches()
  28. {
  29.     if( !`exists getActiveFluidsShapes` ) {
  30.         source "getFluidShape.mel";
  31.     }
  32.  
  33.     string $fluidShapes[] = `getActiveFluidShapes`;    
  34.     for( $fluid in $fluidShapes ) {
  35.         setupFluidPBCache( $fluid );
  36.     }
  37. }
  38.  
  39. global proc setupFluidPBCache( string $fluid)
  40. //
  41. // Description:
  42. //     If there's not already a cache connected to the diskCache IC
  43. //     create it, else clear the existing cache
  44. //     make the cache writeable, save the fluid, and reset the
  45. //     writeableness to its former state
  46. //    
  47. {
  48.     if( `connectionInfo -id ($fluid + ".diskCache")` == 0 ) {
  49.         string $sel[] =`ls -sl`;
  50.         string $cacheName = uniqueCacheName($fluid, ".mcfp"); 
  51.         string $dskC = `createNode -n ("cache_"+$fluid) diskCache`; 
  52.         setAttr -type "string" ($dskC + ".hiddenCacheName") $cacheName;
  53.         setAttr -type "string" ($dskC + ".cacheType") "mcfp";
  54.         connectAttr ($dskC + ".diskCache") ($fluid + ".diskCache");
  55.         select -r $sel;
  56.     }
  57. }
  58.  
  59. global proc doFluidsDiskCache( int $version, string $args[] )
  60. //
  61. // Description:
  62. //    
  63. //    
  64. {
  65.     if(( $version < 1 ) || ( size( $args ) < 10 )) {
  66.         error( "Incorrect version/argument list" );
  67.         return;
  68.     }
  69.  
  70.     string     $cacheType             = $args[0];
  71.     int     $rangeMode             = $args[1];
  72.     int     $sampling              = $args[2];
  73.     float      $diskCacheStartTime = $args[3];
  74.     float      $diskCacheEndTime   = $args[4];
  75.     int        $samplingRate       = $args[5];
  76.  
  77.     int     $uiSettings[]       = { int( $args[6]),    // density
  78.                                         $args[7],     // velocity
  79.                                         $args[8],     // temperature
  80.                                         $args[9],     // reaction
  81.                                         $args[10],     // color
  82.                                         $args[11] };// texture coords
  83.  
  84.     if( !`exists getActiveFluidsShapes` ) {
  85.         source "getFluidShape.mel";
  86.     }
  87.  
  88.     // Make sure that we have a fluid selected
  89.     // or warn the user and fail
  90.     //
  91.     string $fluidShapes[] = getActiveFluidShapes();
  92.     if (size($fluidShapes) == 0)
  93.     {
  94.         warning("No fluids selected");
  95.         return;
  96.     }
  97.  
  98.     // If there is already a diskCache node for one of the
  99.     // fluids, we really can't go about creating another
  100.     // one until the user deletes the existing one.  We'll
  101.     // call this an error condition...
  102.     //
  103.     for( $f in $fluidShapes ) {
  104.         if( `fluidCacheInfo -q -playback -hasCache $f` ) {
  105.             error( "Create Cache: " + $f + " already has a cache. " +
  106.                    "Use \'Delete Cache\' to remove it, or \'Append to " +
  107.                    "Cache\' to add more frames to the end of the cache." );
  108.             break;
  109.         }
  110.     }
  111.  
  112.     // make sure that we know where the Fluids Cache goes
  113.     //
  114.     verifyWorkspaceFileRule( "diskCache", "data" );
  115.  
  116.     setupActiveFluidPBCaches; 
  117.  
  118.     // Just to make sure either autoSave or the confirm box
  119.     // kicks in if there might be data loss, before starting
  120.     // to create the cache.
  121.     // 
  122.     string $ctx = `currentCtx -q`;
  123.     if( $ctx == "artFluidAttrContext" ) {
  124.         artFluidAttrCtx -e -doAutoSave artFluidAttrContext;
  125.     }
  126.  
  127.     if( !`exists fluidPlaybackCaches_disableUnselected` ) {
  128.         source "fluidPlaybackCaches.mel";
  129.     }
  130.     string $changedCaches[] = fluidPlaybackCaches_disableUnselected();
  131.  
  132.     string $cmd;
  133.     // do nothing if there is no diskCache
  134.     string $allDiskCaches[] = `ls -type "diskCache"`;
  135.     if( size($allDiskCaches) < 1 ) {
  136.         string $msg = "No diskCache nodes found.  No caches to create.";
  137.         warning $msg;
  138.         return;
  139.     }
  140.  
  141.     // Verify all diskCache files have unique names
  142.     int $n, $m;
  143.     for($n = 1; $n < size($allDiskCaches); $n++) {
  144.         string $cacheName = `getAttr ($allDiskCaches[$n] + ".cacheName")`;
  145.         if( size($cacheName) == 0 )
  146.             $cacheName = `getAttr ($allDiskCaches[$n] + ".hiddenCacheName")`;
  147.         for( $m = 0; $m < $n; $m++) {
  148.             string $preCacheName = `getAttr ($allDiskCaches[$m] + ".cacheName")`;
  149.             if( size($preCacheName) == 0 )
  150.                 $prevCacheName = `getAttr ($allDiskCaches[$m] + ".hiddenCacheName")`;
  151.             if( $cacheName == $preCacheName ) {
  152.                 string $msg = ( "Disk cache is not created because " + 
  153.                                 $allDiskCaches[$m] + 
  154.                                 " and " + 
  155.                                 $allDiskCaches[$n] + 
  156.                                 " have disk cache name conflict, and one of them has to be renamed." );
  157.                 error $msg;
  158.                 return;
  159.             }
  160.         }
  161.     }
  162.  
  163.     verifyWorkspaceFileRule( "diskCache", "data" );
  164.  
  165.     string $frameRangeOption = "Time Slider";
  166.  
  167.     if( $rangeMode == 1 ) {
  168.         $frameRangeOption = "Render Globals";
  169.     } else if( $rangeMode == 2 ) {
  170.         $frameRangeOption = "Time Slider";
  171.     } else if( $rangeMode == 3 ) {
  172.         $frameRangeOption = "Start/End";
  173.     }                               
  174.  
  175.     string $samplingType   = "";
  176.     if( $sampling == 1 ) {
  177.         $samplingType = "-os";
  178.     }
  179.  
  180.     if( $frameRangeOption == "Start/End" ) {
  181.         $cmd =  "diskCache" + " -frt \"" + $frameRangeOption + "\"" +
  182.                               " -st " + $diskCacheStartTime +
  183.                               " -et " + $diskCacheEndTime +
  184.                               " "     + $samplingType + 
  185.                               " -ct " + $cacheType + 
  186.                               " -sr  " + $samplingRate;
  187.     } else {
  188.         // $frameRangeOption == "Time Slider" or "Render Globals"
  189.         $cmd =  "diskCache" + " -frt \"" + $frameRangeOption + "\"" +
  190.                               " "     + $samplingType + 
  191.                               " -ct " + $cacheType + 
  192.                               " -sr " + $samplingRate;
  193.     }
  194.  
  195.     // Make sure the fluidShapes have their "what-to-cache" attrs
  196.     // updated with the settings in the option vars.  And then, make
  197.     // sure we ony affect enabled cache nodes.
  198.     //
  199.     applyFluidDiskCacheOptions( $uiSettings, "Create Cache", 
  200.                                 "Add to Cache" ); 
  201.  
  202.     eval( $cmd + " -enabledCachesOnly " );
  203.  
  204.     fluidPlaybackCaches_enable( $changedCaches );
  205.  
  206.     // Since it's the actual reading of the diskCache header
  207.     // that sets the startTime and endTime attrs on the diskCache
  208.     // node, we'll do a cacheInfo query for each fluid.
  209.     // 
  210.     // This will force the initial attribute editor start/end
  211.     // values to display correctly.
  212.     // 
  213.     for( $f in $fluidShapes ) {
  214.         fluidCacheInfo -playback -startFrame $f;
  215.     }
  216. }
  217.